#include "inc_test.h"

// #define MIN_STACKSIZE   (4096) /* 注意redzone,*/
#define TEST_NR		 (1000000)

CROUT_STRUCT *crs[1];
static void *rout(void *arg){
	unsigned long nr = (unsigned long)arg;
	// printf("[%ld]rout\n", nr);
	
	return (void *)nr;
}

void test_basicreset(){
	CROUT_ATTR test_attr;
	test_attr.share_stack = NULL;
	struct timespec ts;
	struct timespec dt;
	word_t cycles0;
	word_t cycles1;

	for(unsigned long idx = 0; idx < 1; idx++){
			
		test_attr.stack_size = MIN_STACKSIZE;
		if (0 != CROUT_CREATE(&crs[idx], &test_attr, rout, NULL_PTR)){
			printf("create failed\n");
			return;
		}
	}
	TIME_STAMP(&ts);
	cycles0 = rdcnt_relax();
	for(unsigned long idx = 0; idx < TEST_NR; idx++){
		CROUT_RESUME(crs[0]);
		CROUT_RESET(crs[0]);
	}
	cycles1 = rdcnt_relax();
	TIME_STAMP(&dt);
	// printf("%lu reset execution time [us] %lu[%ld]\n", (unsigned long)time, TIME_DELTA_US(&ts, &dt), cycles1-cycles0);
	printf("[%8llu ns/ops] %lu reset time in us: %llu (%lld cycles/op)\n", TIME_DELTA_NS(&ts, &dt)/TEST_NR, \
	(unsigned long)TEST_NR, TIME_DELTA_US(&ts, &dt), ((llong_t)cycles1-cycles0)/TEST_NR);
	fprintf(stderr, "%llu\n", TIME_DELTA_US(&ts, &dt));



	for(unsigned long idx = 0; idx < 1; idx++){
		CROUT_RELEASE(crs[idx]);
	}
}

int main(){
	test_basicreset();
	return 0;
}
